<template>
  <div :id="id" :class="className" :style="{height:height,width:width}" />
</template>

<script>
import resize from "./mixins/resize";

export default {
  props: {
    className: {
      type: String,
      default: "chart"
    },
    id: {
      type: String,
      default: "chart"
    },
    width: {
      type: String,
      default: "100%"
    },
    height: {
      type: String,
      default: "200px"
    },
    autoResize: {
      type: Boolean,
      default: true
    }
  },
  data() {
    return {
      chart: null
    };
  },
  mounted() {
    this.$nextTick(() => {
      this.initChart();
    });
  },
  beforeDestroy() {
    if (!this.chart) {
      return;
    }
    this.chart.dispose();
    this.chart = null;
  },
  methods: {
    initChart() {
      this.chart = echarts.init(this.$el, "macarons");
      this.setOptions(this.chartData);
    },
    setOptions({ DayData } = {}) {
      this.chart.setOption({
        // 悬浮显示
        tooltip: {
          trigger: "item",
          formatter: "{a} <br/>{b} : {c} ({d}%)"
        },
        legend: {
          orient: "vertical",
          top: "middle",
          bottom: 0,
          top: 30,
          left: "right",
          data: [
            "三合一传感器",
            "空气温度传感器",
            "空气湿度传感器",
            "土壤温度传感器",
            "土壤湿度传感器",
            "土壤pm值传感器"
          ],
          textStyle: {
            color: "#e6e6e6"
          }
        },
        color: [
          "#ffff99",
          "#24ae94",
          "#ffb3e5",
          "#f5898b",
          "#308e92",
          "#0099cc",
          "#00b300"
        ],
        backgroundColor: "transparent",
        tooltip: {
          show: true,
          type: "axis"
        },
        series: [
          {
            name: "设备信息",
            type: "pie",
            clockWise: false, //顺时加载
            hoverAnimation: true, //鼠标移入变大
            radius: [30, 65],
            center: ["30%", "50%"],
            roseType: "radius",
            itemStyle: {
              normal: {
                label: {
                  show: false,
                  position: "outside"
                },
                labelLine: {
                  show: false,
                  length: 15,
                  smooth: 0.5
                },
                shadowBlur: 10,
                shadowColor: "rgba(0, 0, 0, 0.2)" //边框阴影
              }
            },
            data: [
              { value: 9, name: "土壤湿度传感器" },
              { value: 9, name: "土壤pm值传感器" },
              { value: 9, name: "空气温度传感器" },
              { value: 1, name: "空气湿度传感器" },
              { value: 1, name: "土壤温度传感器" },
              { value: 2, name: "三合一传感器" },
            ]
          }
        ]
      });
    }
  }
};
</script>